#include "Remote.h"
#include "Chassis.h"
#include <string.h>

void Remote_Init(void)
{
    AttachInterrupt_UART(&REMOTE_UART, 64, Remote_Callback);
}

/**
 * 遥控串口中断回调函数
 */
void Remote_Callback(uint8_t *pData, uint8_t size)
{
    if (strncmp((char *)pData, "y10000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, 10000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y1000", 5) == 0)
    {
        Chassis_SetPos(chassis.setPx, 1000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y2000", 5) == 0)
    {
        Chassis_SetPos(chassis.setPx, 2000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y5000", 5) == 0)
    {
        Chassis_SetPos(chassis.setPx, 5000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y9000", 5) == 0)
    {
        Chassis_SetPos(chassis.setPx, 9000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y11000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, 11000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y0", 2) == 0)
    {
        Chassis_SetPos(chassis.setPx, 0, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y-1000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, -1000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y-2000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, -2000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y-5000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, -5000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "y-9000", 6) == 0)
    {
        Chassis_SetPos(chassis.setPx, -10000, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "re", 2) == 0)
    {
        HAL_NVIC_SystemReset();
    }
    else if (strncmp((char *)pData, "x1000", 5) == 0)
    {
        Chassis_SetPos(1000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x2000", 5) == 0)
    {
        Chassis_SetPos(2000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x5000", 5) == 0)
    {
        Chassis_SetPos(5000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x0", 2) == 0)
    {
        Chassis_SetPos(0, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x-10000", 7) == 0)
    {
        Chassis_SetPos(-10000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x-1000", 6) == 0)
    {
        Chassis_SetPos(-1000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x-2000", 6) == 0)
    {
        Chassis_SetPos(-2000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x-5000", 6) == 0)
    {
        Chassis_SetPos(-5000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "x-9000", 6) == 0)
    {
        Chassis_SetPos(-9000, chassis.setPy, chassis.setYaw);
    }
    else if (strncmp((char *)pData, "a90", 3) == 0)
    {
        Chassis_SetPos(chassis.setPx, chassis.setPy, RAD(90));
    }
    else if (strncmp((char *)pData, "a0", 2) == 0)
    {
        Chassis_SetPos(chassis.setPx, chassis.setPy, RAD(0));
    }
    else if (strncmp((char *)pData, "a-90", 4) == 0)
    {
        Chassis_SetPos(chassis.setPx, chassis.setPy, RAD(-90));
    }
    else if (strncmp((char *)pData, "re", 2) == 0)
    {
        HAL_NVIC_SystemReset();
    }
}